/* Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.*/
(function(a){function b(a){return a&&a.Object===Object?a:null}var c={"function":!0,object:!0},d=c[typeof exports]&&exports&&!exports.nodeType?exports:null,e=c[typeof module]&&module&&!module.nodeType?module:null,f=b(d&&e&&"object"==typeof global&&global),g=b(c[typeof self]&&self),h=b(c[typeof window]&&window),i=(e&&e.exports===d?d:null,b(c[typeof this]&&this)),j=f||h!==(i&&i.window)&&h||g||i||Function("return this")();"function"==typeof define&&define.amd?define(["./rx"],function(b,c){return a(j,c,b)}):"object"==typeof module&&module&&module.exports===d?module.exports=a(j,module.exports,require("./rx")):j.Rx=a(j,{},j.Rx)}).call(this,function(a,b,c,d){function e(a){return function(){try{return a.apply(this,arguments)}catch(b){return G.e=b,G}}}function f(a,b){return new J(a,b)}function g(){for(var a=arguments.length,b=new Array(a),c=0;a>c;c++)b[c]=arguments[c];return b}var h=c.Observable,i=h.prototype,j=c.ObservableBase,k=c.internals.AbstractObserver,l=c.FlatMapObservable,m=h.concat,n=h.defer,o=h.empty,p=c.Disposable.empty,q=c.CompositeDisposable,r=c.SerialDisposable,s=c.SingleAssignmentDisposable,t=c.internals.Enumerable,u=t.of,v=c.Scheduler.currentThread,w=c.AsyncSubject,x=c.Observer,y=c.internals.inherits,z=c.internals.addProperties,A=c.helpers,B=A.noop,C=A.isPromise,D=A.isFunction,E=(c.helpers.isIterable,c.helpers.isArrayLike,c.Scheduler.isScheduler),F=h.fromPromise,G={e:{}},H=c.internals.tryCatch=function(a){if(!D(a))throw new TypeError("fn must be a function");return e(a)},I="function"==typeof Symbol&&Symbol.iterator||"_es6shim_iterator_";a.Set&&"function"==typeof(new a.Set)["@@iterator"]&&(I="@@iterator");c.doneEnumerator={done:!0,value:d},c.helpers.isIterable=function(a){return a&&a[I]!==d},c.helpers.isArrayLike=function(a){return a&&a.length!==d};c.helpers.iterator=I;var J=function(a){function b(a,b){this.c=a,this.s=b}return y(b,a),b.prototype[I]=function(){var a=this;return{next:function(){return a.c()?{done:!1,value:a.s}:{done:!0,value:void 0}}}},b}(t);i.letBind=i.let=function(a){return a(this)},h["if"]=function(a,b,c){return n(function(){return c||(c=o()),C(b)&&(b=F(b)),C(c)&&(c=F(c)),"function"==typeof c.now&&(c=o(c)),a()?b:c})},h["for"]=h.forIn=function(a,b,c){return u(a,b,c).concat()};var K=h["while"]=h.whileDo=function(a,b){return C(b)&&(b=F(b)),f(a,b).concat()};i.doWhile=function(a){return m([this,K(a,this)])},h["case"]=function(a,b,c){return n(function(){C(c)&&(c=F(c)),c||(c=o()),E(c)&&(c=o(c));var d=b[a()];return C(d)&&(d=F(d)),d||c})};var L=function(a){function b(b,c,d){this.source=b,this._fn=c,this._scheduler=d,a.call(this)}function c(a,b){var c,d=a[0],e=a[1];if(!(d.q.length>0))return void(d.isAcquired=!1);c=d.q.shift();var f=new s;d.d.add(f),f.setDisposable(c.subscribe(new M(d,e,f))),b([d,e])}return y(b,a),b.prototype._ensureActive=function(a){var b=!1;a.q.length>0&&(b=!a.isAcquired,a.isAcquired=!0),b&&a.m.setDisposable(this._scheduler.scheduleRecursive([a,this],c))},b.prototype.subscribeCore=function(a){var b=new r,c=new q(b),d={q:[],m:b,d:c,activeCount:0,isAcquired:!1,o:a};return d.q.push(this.source),d.activeCount++,this._ensureActive(d),c},b}(j),M=function(a){function b(b,c,d){this._s=b,this._p=c,this._m1=d,a.call(this)}return y(b,a),b.prototype.next=function(a){this._s.o.onNext(a);var b=H(this._p._fn)(a);return b===G?this._s.o.onError(b.e):(this._s.q.push(b),this._s.activeCount++,void this._p._ensureActive(this._s))},b.prototype.error=function(a){this._s.o.onError(a)},b.prototype.completed=function(){this._s.d.remove(this._m1),this._s.activeCount--,0===this._s.activeCount&&this._s.o.onCompleted()},b}(k);i.expand=function(a,b){return E(b)||(b=v),new L(this,a,b)};var N=function(a){function b(b,c){this._sources=b,this._cb=c,a.call(this)}return y(b,a),b.prototype.subscribeCore=function(a){if(0===this._sources.length)return a.onCompleted(),p;for(var b=this._sources.length,c={finished:!1,hasResults:new Array(b),hasCompleted:new Array(b),results:new Array(b)},d=new q,e=0,f=this._sources.length;f>e;e++){var g=this._sources[e];C(g)&&(g=F(g)),d.add(g.subscribe(new O(a,c,e,this._cb,d)))}return d},b}(j),O=function(a){function b(b,c,d,e,f){this._o=b,this._s=c,this._i=d,this._cb=e,this._subs=f,a.call(this)}return y(b,a),b.prototype.next=function(a){this._s.finished||(this._s.hasResults[this._i]=!0,this._s.results[this._i]=a)},b.prototype.error=function(a){this._s.finished=!0,this._o.onError(a),this._subs.dispose()},b.prototype.completed=function(){if(!this._s.finished){if(!this._s.hasResults[this._i])return this._o.onCompleted();this._s.hasCompleted[this._i]=!0;for(var a=0;a<this._s.results.length;a++)if(!this._s.hasCompleted[a])return;this._s.finished=!0;var b=H(this._cb).apply(null,this._s.results);if(b===G)return this._o.onError(b.e);this._o.onNext(b),this._o.onCompleted()}},b}(k);h.forkJoin=function(){for(var a=arguments.length,b=new Array(a),c=0;a>c;c++)b[c]=arguments[c];var d=D(b[a-1])?b.pop():g;return Array.isArray(b[0])&&(b=b[0]),new N(b,d)},i.forkJoin=function(){for(var a=arguments.length,b=new Array(a),c=0;a>c;c++)b[c]=arguments[c];return Array.isArray(b[0])?b[0].unshift(this):b.unshift(this),h.forkJoin.apply(null,b)},i.manySelect=i.extend=function(a,b){E(b)||(b=c.Scheduler.immediate);var d=this;return n(function(){var c;return d.map(function(a){var b=new P(a);return c&&c.onNext(a),c=b,b}).tap(B,function(a){c&&c.onError(a)},function(){c&&c.onCompleted()}).observeOn(b).map(a)},d)};var P=function(a){function b(b){a.call(this),this.head=b,this.tail=new w}return y(b,a),z(b.prototype,x,{_subscribe:function(a){var b=new q;return b.add(v.schedule(this,function(c,d){a.onNext(d.head),b.add(d.tail.mergeAll().subscribe(a))})),b},onCompleted:function(){this.onNext(h.empty())},onError:function(a){this.onNext(h["throw"](a))},onNext:function(a){this.tail.onNext(a),this.tail.onCompleted()}}),b}(h),Q=function(a){function b(b){this.source=b,a.call(this)}return y(b,a),b.prototype.subscribeCore=function(a){var b=new s,c=new q,d={hasCurrent:!1,isStopped:!1,o:a,g:c};return c.add(b),b.setDisposable(this.source.subscribe(new R(d))),c},b}(j),R=function(a){function b(b){this._s=b,a.call(this)}function c(b,c){this._s=b,this._i=c,a.call(this)}return y(b,a),b.prototype.next=function(a){if(!this._s.hasCurrent){this._s.hasCurrent=!0,C(a)&&(a=F(a));var b=new s;this._s.g.add(b),b.setDisposable(a.subscribe(new c(this._s,b)))}},b.prototype.error=function(a){this._s.o.onError(a)},b.prototype.completed=function(){this._s.isStopped=!0,!this._s.hasCurrent&&1===this._s.g.length&&this._s.o.onCompleted()},y(c,a),c.prototype.next=function(a){this._s.o.onNext(a)},c.prototype.error=function(a){this._s.o.onError(a)},c.prototype.completed=function(){this._s.g.remove(this._i),this._s.hasCurrent=!1,this._s.isStopped&&1===this._s.g.length&&this._s.o.onCompleted()},b}(k);return i.switchFirst=function(){return new Q(this)},i.flatMapFirst=i.exhaustMap=function(a,b,c){return new l(this,a,b,c).switchFirst()},i.flatMapWithMaxConcurrent=i.flatMapMaxConcurrent=function(a,b,c,d){return new l(this,b,c,d).merge(a)},c});
//# sourceMappingURL=rx.experimental.map